
/**
 * 自定义的Map对象
 */

function JsMap() {
	this.elements = new Array();
	this.size = function() {
		return this.elements.length;
	}
	this.put = function(_key, _value) {
		if(this.containsKey(_key)){
			this.remove(_key);
		}
		this.elements.push({
			key : _key,
			value : _value
		});
	}

	this.remove = function(_key) {
		var bln = false;
		try {
			out:for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					this.elements.splice(i, 1);
					bln = true;
					break out;
				}
			}
			return true;
		} catch (e) {
			bln = false;
		}
		return bln;
	}
	
	this.removeAll = function() {
		var bln = false;
		try {
			this.elements= [];
			return true;
		} catch (e) {
			bln = false;
		}
		return bln;
	}

	this.containsKey = function(_key) {
		var bln = false;
		try {
			out:for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					bln = true;
					break out;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	}

	this.get = function(_key) {
		try {
			for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					return this.elements[i];
				}
			}
		} catch (e) {
			return null;
		}
	}
	
	this.getIndex = function(_index) {
		try {
			return this.elements[_index];
		} catch (e) {
			return null;
		}
	}
}